//返回值为需不需要关闭窗口
function yesOperator(){
    var retValue=addData();
    return retValue;
}
function updateLoad(){
    var params = $$.getQueryString();
    $$.ajax({
        url:"/rest/IotTaskBusiness/query",
        data : {
            id : params.rowId
        },
        success : function(data){
            $("#b_id").val(data.id);
            $("#b_taskCode").val(data.taskCode);

            $("#b_taskName").val(data.taskName);

            $("#b_taskPeriod").val(data.taskPeriod);

            $("#b_taskHs").val(data.taskHs);

            $("#b_taskUnit").val(data.taskUnit);

            $("#b_taskExpect").val(data.taskExpect);

            $("#b_taskGroup").val(data.taskGroup);

            $("#b_taskMain").val(data.taskMain);

            $("#b_iotTable").val(data.iotTable);

            $("#b_iotTime").val(data.iotTime);

            $("#b_iotDexpr").val(data.iotDexpr);

            $("#b_iotExpr").val(data.iotExpr);

            $("#b_uuid").val(data.uuid);

            $("#b_status").val(data.status);

            $("#b_rowSort").val(data.rowSort);

            $("#b_remarks").val(data.remarks);

            var status=data.status;

            $("input[name^='b_status_']").each(function(){

                if($(this).val()==status){

                    this.checked='checked';

                }

            });


            $("#b_taskCodeOld").val(data.taskCode);

            var newValue={};
            newValue.taskCode=$("#b_taskCode").val();
            newValue.taskPeriod=$("#b_taskPeriod").val();
            newValue.taskHs=$("#b_taskHs").val();
            newValue.taskUnit=$("#b_taskUnit").val();
            newValue.taskExpect=$("#b_taskExpect").val();
            newValue.taskGroup=$("#b_taskGroup").val();
            newValue.taskMain=$("#b_taskMain").val();
            newValue.iotTable=$("#b_iotTable").val();
            newValue.iotTime=$("#b_iotTime").val();
            newValue.iotDexpr=$("#b_iotDexpr").val();
            newValue.iotExpr=$("#b_iotExpr").val();

            $("#b_oldValue").val(JSON.stringify(newValue));


        }
    });



}
function returnHome(){
    $$.goUrl("/iot/task/task_list.html")
}
function validForm(){
	var ret=$('#theform').valid();

  return ret;
}
function addData(){

    var newValue={};
    newValue.taskCode=$("#b_taskCode").val();
    newValue.taskPeriod=$("#b_taskPeriod").val();
    newValue.taskHs=$("#b_taskHs").val();
    newValue.taskUnit=$("#b_taskUnit").val();
    newValue.taskExpect=$("#b_taskExpect").val();
    newValue.taskGroup=$("#b_taskGroup").val();
    newValue.taskMain=$("#b_taskMain").val();
    newValue.iotTable=$("#b_iotTable").val();
    newValue.iotTime=$("#b_iotTime").val();
    newValue.iotDexpr=$("#b_iotDexpr").val();
    newValue.iotExpr=$("#b_iotExpr").val();

    if(JSON.stringify(newValue) != $("#b_oldValue").val()){
        $("#b_uuid").val(Math.uuid());
    }
    if( $("#b_uuid").val().length<1){
        $("#b_uuid").val(Math.uuid());
    }






    //alert("=====addData======");
    var param = {};
    var validFormRet;
    $$.form({
        async:false,
        able:function(){
            validFormRet=false;
        },
        checkForm: validForm,
        success: function () {
            validFormRet= true;
            returnHome();

        }
    });
    return validFormRet;
    /**/
}

function taskFormValid() {
    $("#theform").validate({
        rules: {
            b_taskCode: {
                required: true,
                minlength: 3
            },
            b_taskName: {
                required: true,
                minlength: 3,
            },
            b_taskHs:{
                required: true,
                minlength: 6,
            },
            b_iotTable:{
                required: true,
                minlength: 6,
            },
            b_taskPeriod:{
                required: true
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errorDevice",
        success: 'valid',
        messages: {
            b_taskPeriod: {
                required: " (必填)"
            },
            b_taskCode: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
                number: "请输入数字",
            },
            b_taskName: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
            },
            b_taskHs:{
                required: " (必填)",
                minlength: " (不能3 个字母)"
            },
            b_iotTable:{
                required: " (必填)",
                minlength: " (不能3 个字母)"
            }
        },
    });
}

$(function () {
    taskFormValid();
    $("#subBtn").on('click',function () {
        //alert("subbtn.click");
        addData();
    });
    $("input[name^='b_status_']").click(function(){
        $("#b_status").val($(this).val());
    });
    $("input[name^='b_taskMain_']").click(function () {
        $("#b_taskMain").val($(this).val());
    });
    var taskTime=new Date();
    laydate.render({
        elem:'#b_taskHs',
        type:'time',
        format: 'HH:mm:ss',
        value: taskTime,
        zIndex: 99
    })

});

